package com.csnz.dao.role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.csnz.dao.BaseDao;
import com.csnz.pojo.Role;
import com.csnz.util.JDBCUtils;

public class RoleDaoImpl implements RoleDao{
	
	

	@Test
	public void test4() throws Exception {
		List<Role> list = getRoleList(JDBCUtils.getConnection());
		list.forEach(System.out::println);
	}


	public List<Role> getRoleList(Connection conn) throws SQLException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		ArrayList<Role> list = null;
		if (conn != null) {
			String sql = "select * from smbms_role";
			Object[] params = {};
			rs = BaseDao.executeQuery(conn, sql, params, ps, rs);
			list = new ArrayList<>();
			while (rs.next()) {
				Role role = new Role();
				role.setId(rs.getInt("id"));
				role.setRoleCode(rs.getString("roleCode"));
				role.setRoleName(rs.getString("roleName"));
				list.add(role);
			}
			JDBCUtils.closeResource(null, ps, rs);
		}
		return list;
	}

}
